<template>
    <h2>添加用户页面</h2>
    <table border="1">
        <tr>
            <td>用户名</td>
            <td><input type="text" v-model="info.Uname" /></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" v-model="info.Upwd"/></td>
        </tr>
        <tr>
            <td colspan="2">
                <button @click="AddUser">添加</button>
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import axios from 'axios';
import {ref} from 'vue'
import {useRouter} from 'vue-router';
const router=useRouter()
const info=ref({
    Uname:'',
    Upwd:''
})
const AddUser=()=>{
    axios.post("https://localhost:44396/api/UserRole/AddUser",
        {
            
                Uname:info.value.Uname,
                Upwd:info.value.Upwd
            
        }
    ).then(res=>{
        if(res.data>0){
            alert("添加成功")
            router.push("/ShowUserRole")
        }else if(res.data==-1){
            alert("用户名重复")
        }else{
            alert("添加失败")
        }
    }).catch(err=>{
        console.log(err)
    })
}



</script>